<template>
<view class="content">
	<view class="author">
		<image src="/static/remao_shop/img/openShop.png" class="img"></image>
	</view>
	<text class="name">热猫店铺</text>
	<image :src="erma" class="ewm"></image>
	<text class="name" style="margin-bottom: 0;">扫一扫，进入店铺</text>
	<view class="btn" @tap="save">保存二维码</view>
</view>
</template>

<script>
import api from "../../../api";
var app = getApp();

export default {
  data() {
    return {
      userId: '',
      erma: ''
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.getEwm();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    getEwm: function () {
      var that = this;
      wx.getStorage({
        key: 'userId',
        success: res => {
          console.log(res);
          this.setData({
            userId: res.data
          });
          app.globalData.request({
            url: api.default.codeWxsharecode,
            data: {
              uid: that.userId,
              scene: that.shopId
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded' // 默认值

            },
            method: 'POST',
            success: res => {
              // wx.arrayBufferToBase64(res)
              console.log(res);
              that.setData({
                erma: res.data
              });
              wx.downloadFile({
                url: res.data,
                success: function (sres) {
                  console.log(sres);
                  that.setData({
                    erma: sres.tempFilePath
                  });
                  console.log(that.erma);
                },
                fail: function (fres) {}
              });
            }
          });
        }
      });
    },

    save() {
      var img = this.erma;
      var that = this;
      wx.saveImageToPhotosAlbum({
        filePath: that.erma,
        success: res => {
          console.log(res);
        }
      });
    }

  }
};
</script>
<style>
@import "./ewm.css";
</style>